import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/data/entities/application/basic_information/change_overhaul_record_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/basic_information/equipment_facilities/parts_accessory_list/parts_accessory_details/parts_accessory_details_controller.dart';

///部件/副件详情
class PartsAccessoryDetailsPage extends StatelessWidget {
  PartsAccessoryDetailsPage({super.key});

  final controller = Get.put(PartsAccessoryDetailsController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '部件/副件详情',
            ),
            body: Container(
              alignment: Alignment.topCenter,
              color: const Color(0xffF5F5F6),
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    Container(
                      height: 38.w,
                      alignment: Alignment.centerLeft,
                      padding: EdgeInsets.only(left: 16.w),
                      child: Text('基本信息', style: TextStyle(fontSize: 12.sp, color: const Color(0xFF7C7D93))),
                    ),
                    Container(
                      height: 2.w,
                      color: const Color(0xFF587DF5),
                    ),
                    Container(
                      color: Colors.white,
                      padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 15.w),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          _getTextView(title: '部件/副件：', value: controller.informationEntity.componentName!),
                          AppGaps.vGap10,
                          _getTextView(title: '规格型号：', value: controller.informationEntity.specsCode!),
                          AppGaps.vGap10,
                          _getTextView(title: '备件号：', value: controller.informationEntity.sparePartCode!),
                          AppGaps.vGap10,
                          _getTextView(title: '单位：', value: controller.informationEntity.unitName!),
                          AppGaps.vGap10,
                          _getTextView(title: '制造厂家/原产地：', value: controller.informationEntity.manufacturer!),
                          AppGaps.vGap10,
                          _getTextView(title: '所用部件：', value: controller.informationEntity.componentsUsed!),
                          AppGaps.vGap10,
                          _getTextView(title: '更换周期/年：', value: controller.informationEntity.changeCycle!),
                          AppGaps.vGap10,
                          _getTextView(title: '检验周期/年：', value: controller.informationEntity.checkCycle!),
                          AppGaps.vGap10,
                          _getTextView(title: '检定周期/年：', value: '${controller.informationEntity.verificationCycle!}'),
                          AppGaps.vGap10,
                          _getTextView(title: '部件类型：', value: controller.informationEntity.deviceTypeName!),
                        ],
                      ),
                    ),
                    //以下内容产品说先隐藏（检修历史）
                    // Container(
                    //   height: 38.w,
                    //   alignment: Alignment.centerLeft,
                    //   padding: EdgeInsets.only(left: 16.w),
                    //   child: Text('更换/校验历史', style: TextStyle(fontSize: 12.sp, color: const Color(0xFF7C7D93))),
                    // ),
                    // Container(
                    //   height: 2.w,
                    //   color: const Color(0xFF587DF5),
                    // ),
                    // Container(
                    //   color: Colors.white,
                    //   child: Row(
                    //     children: [
                    //       Expanded(
                    //         child: Container(
                    //           padding: EdgeInsets.symmetric(vertical: 15.w),
                    //           child: Text('更换',
                    //               textAlign: TextAlign.right,
                    //               style: TextStyle(
                    //                 fontWeight: FontWeight.w500,
                    //                 fontSize: 14.sp,
                    //                 color: controller.type == 0 ? const Color(0xFF5C6DFF) : const Color(0xFFA0A7B5),
                    //               )),
                    //         ).clickOnce(() {
                    //           controller.onClickType(0);
                    //         }),
                    //       ),
                    //       AppGaps.hGap20,
                    //       Text('/', style: TextStyle(fontSize: 14.sp, color: const Color(0xFF7C7D93))),
                    //       AppGaps.hGap20,
                    //       Expanded(
                    //         child: Container(
                    //           padding: EdgeInsets.symmetric(vertical: 15.w),
                    //           child: Text('校验',
                    //               style: TextStyle(
                    //                 fontWeight: FontWeight.w500,
                    //                 fontSize: 14.sp,
                    //                 color: controller.type == 1 ? const Color(0xFF5C6DFF) : const Color(0xFFA0A7B5),
                    //               )),
                    //         ).clickOnce(() {
                    //           controller.onClickType(1);
                    //         }),
                    //       ),
                    //     ],
                    //   ),
                    // ),
                    // Container(
                    //   height: 1.w,
                    //   color: const Color(0xFF587DF5).withOpacity(0.2),
                    // ),
                    // Container(
                    //   color: Colors.white,
                    //   child: ListView.builder(
                    //       padding: EdgeInsets.symmetric(horizontal: 27.w, vertical: 22.w),
                    //       itemCount: controller.informationEntity.children!.length,
                    //       shrinkWrap: true,
                    //       physics: const BouncingScrollPhysics(),
                    //       itemBuilder: (context, index) {
                    //         return CustomIntrinsicCircleLine(
                    //           showWidget: _getTrainView(controller.informationEntity.children![index]),
                    //         );
                    //       }),
                    // ),
                  ],
                ),
              ),
            ),
          );
        });
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value, Color? valueColor}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: 120.w,
          child: Text(
            title,
            style: TextStyle(
              fontSize: 13.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: const Color(0xffA0A7B5),
            ),
          ),
        ),
        Expanded(
            child: Text(
          value,
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: valueColor ?? const Color(0xff495061),
          ),
        ))
      ],
    );
  }

  ///获取历史显示
  Widget _getTrainView(ChangeOverhaulRecordEntity value) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          children: [
            Expanded(
              child: Text(
                value.changeOverhaulDate!,
                style: TextStyle(
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w400,
                  color: const Color(0xff262F38),
                ),
              ),
            ),
            Container(
              height: 16.w,
              width: 16.w,
              decoration: BoxDecoration(
                color: const Color(0xff5C6DFF),
                border: Border.all(
                  color: const Color(0xffEEF0FF),
                  width: 4.w,
                ),
                borderRadius: BorderRadius.circular(90.r),
              ),
            ),
            AppGaps.hGap8,
            Text(
              value.changeOverhaulPerson!,
              style: TextStyle(
                fontSize: 14.sp,
                fontWeight: FontWeight.w400,
                color: const Color(0xff5C6DFF),
              ),
            )
          ],
        ),
        AppGaps.vGap10,
        Row(
          children: [
            Text(
              controller.type == 0 ? '更换' : '校验',
              style: TextStyle(
                fontSize: 13.sp,
                height: 1.2,
                fontWeight: FontWeight.w400,
                color: const Color(0xff262F38),
              ),
            ),
            Text(
              '   - -- -- -   ',
              style: TextStyle(
                fontSize: 13.sp,
                height: 1.2,
                fontWeight: FontWeight.w400,
                color: const Color(0xff5C6DFF),
              ),
            ),
            Text(
              _getDeadlineStatusTxt(value.deadlineStatus!),
              style: TextStyle(
                fontSize: 12.sp,
                height: 1.2,
                fontWeight: FontWeight.w400,
                color: const Color(0xff5C6DFF),
              ),
            ),
          ],
        ),
        AppGaps.vGap10,
        _getTextView(title: '截至时间：', value: value.deadline!),
        AppGaps.vGap10,
        _getTextView(title: '备注：', value: value.notes!),
        AppGaps.vGap20,
      ],
    );
  }

  /// 获取状态字段
  /// 0，准时；1，提前；2，超时
  String _getDeadlineStatusTxt(String deadlineStatus) {
    switch (deadlineStatus) {
      case '0':
        return '准时';
      case '1':
        return '提前';
      case '2':
        return '超时';
      default:
        return '';
    }
  }
}
